Candle = cc.Node.extend({
	ctor:function(p){
		this._super();
		p.addChild(this, 10, TAG_CANDLE);
		this.init();
	},
	init : function(){
		this.setCascadeOpacityEnabled(true);

		var candle1= new Button(this, 11, TAG_CANDLE1, "#yiqi/candle1.png",this.callback);
		candle1.setPosition(200,300);
		candle1.setVisible(false);
		var candle2= new Button(this, 10, TAG_CANDLE2, "#yiqi/candle1.png",this.callback);
		candle2.setPosition(990,280);
		candle2.setVisible(false);
		var candle3= new Button(this, 10, TAG_CANDLE3, "#yiqi/candle1.png",this.callback);
		candle3.setPosition(810,280);
		candle3.setVisible(false);
		var candle4= new Button(this, 10, TAG_CANDLE4, "#yiqi/candle2.png",this.callback);
		candle4.setPosition(430,400);
		candle4.setVisible(false);
		
		var glass = new Button(this, 11, TAG_GLASS, "#yiqi/side_glass.png",this.callback);
		glass.setVisible(false);
		glass.setScaleY(0.5);
		glass.setPosition(900,310);
		var desk = new Button(this, 11, TAG_DESK, "#yiqi/side_desk.png",this.callback);
		desk.setVisible(false);
		desk.setPosition(909,200);
		
		var showCandle2 = null;
		var showCandle3 = null;
		
	},
	
	candle2_action:function(){
		var candle = this.getChildByTag(TAG_CANDLE2);
		var move = cc.moveBy(3, 40, 0);
		var seq = cc.sequence(move);
		candle.runAction(seq);
		
	},
	
	candle3_action:function(){
		var candle = this.getChildByTag(TAG_CANDLE3);
		var move = cc.moveBy(3, -40, 0);
		var seq = cc.sequence(move);
		candle.runAction(seq);
	},
	candle4_action:function(){
		var candle = this.getChildByTag(TAG_CANDLE4);
		var move = cc.moveBy(3, 20, 34.6);
		var seq = cc.sequence(move);
		candle.runAction(seq);
	},
	
	candle2_back:function(){
		var candle = this.getChildByTag(TAG_CANDLE2);
		var move = cc.moveBy(3, 40, 0);
		var seq = cc.sequence(move.reverse());
		candle.runAction(seq);

	},

	candle3_back:function(){
		var candle = this.getChildByTag(TAG_CANDLE3);
		var move = cc.moveBy(3, -40, 0);
		var seq = cc.sequence(move.reverse());
		candle.runAction(seq);
	},
	candle4_back:function(){
		var candle = this.getChildByTag(TAG_CANDLE4);
		var move = cc.moveBy(3, 20, 34.6);
		var seq = cc.sequence(move.reverse());
		candle.runAction(seq);
	},
	callback:function(p){
		var action = gg.flow.flow.action;
		var func=cc.callFunc(function() {
			gg.flow.next();
		},this);
		var reflash = cc.callFunc(function(){
			gg.flow.refresh();
		},this);
		switch(p.getTag()){	
		case TAG_CANDLE1:
			if(action==ACTION_DO1){				
				var seq = cc.sequence(cc.moveTo(1,380,330),
						cc.callFunc(function() {		
							this.getChildByTag(TAG_CANDLE4).setVisible(true);
							this.getChildByTag(TAG_CANDLE2).setVisible(true);
							this.getChildByTag(TAG_CANDLE3).setVisible(true);
							this.getChildByTag(TAG_GLASS).setVisible(true);
							this.getChildByTag(TAG_DESK).setVisible(true);
							var show = new ShowTip("使用另一只蜡烛"+"\n"+"放置在镜面后，"+"\n"+"与像等大的位置上",cc.p(1000,500));
							this.showCandle2 = new ShowTip("成像位置",cc.p(950,140));
							this.showCandle3 = new ShowTip("蜡烛位置",cc.p(700,140));
						},this),cc.delayTime(1),func);		
			}else if(action==ACTION_DO2){
				var move = cc.moveBy(3,-20,-34.6);
				var seq = null;
				if(!this.flag)
					{
					this.flag = true;
					seq = cc.sequence(cc.spawn(move,
						cc.callFunc(function() {	
							this.candle2_action();
							this.candle3_action();
							this.candle4_action();	
							this.showCandle2 = new ShowTip("成像位置",cc.p(950,140));
							this.showCandle3 = new ShowTip("蜡烛位置",cc.p(700,140));
						},this)),cc.delayTime(1),reflash);
					}
				else{
					this.flag = false;
					seq = cc.sequence(cc.spawn(move.reverse(),
							cc.callFunc(function() {	
								this.candle2_back();
								this.candle3_back();
								this.candle4_back();	
								this.showCandle2 = new ShowTip("成像位置",cc.p(950,140));
								this.showCandle3 = new ShowTip("蜡烛位置",cc.p(700,140));
							},this)),cc.delayTime(1),reflash);
					}
			}
			p.runAction(seq);
			break;
		}
	},
});